package com.ymatou.iapi.trading.operate.testcase;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Map;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.trading.operate.parameter.PlaceOrderResp;
import com.ymatou.iapi.trading.operate.parameter.RiskControlNotifyBean;
import com.ymatou.iapi.trading.operate.service.RiskControlNotifyCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P1;
import com.ymt.utils.tag.P2;
import com.ymttest.business.service.OrderCallService;
import com.ymttest.database.sqlwapper.DefaultWapper;
/**
*风控通知
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_RiskControlNotify{
	private static final HashMap String = null;
	private static RiskControlNotifyBean riskcontrolnotifyBean;
	private static RiskControlNotifyCall riskcontrolnotifyCall;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("风控通知");
	}

	@Before
	public void caseUp() {
		riskcontrolnotifyBean=new RiskControlNotifyBean();
		riskcontrolnotifyCall=new RiskControlNotifyCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(riskcontrolnotifyCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_RiskControlNotify_001() {
		Logger.start(true,"风控通知审核,成功");
		try {
			//创建订单
			Logger.comment("前置数据准备");
			PlaceOrderResp placeOrderResp=new OrderCallService().createM2cOrder();

			int orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			int sellerId =placeOrderResp.getOrderList().get(0).getSellerId();
			int userId =placeOrderResp.getUserId();         
			int tradingId = placeOrderResp.getTradingId();
			BigDecimal totalPrice =  placeOrderResp.getPayAmount();// 支付金额

						
			new OrderCallService().orderPayRequest(userId, totalPrice, tradingId);
			Map paramExt = new HashMap<String, String>();
			paramExt.put("Status", "auditing");			
			//参数
			riskcontrolnotifyBean.setOrderId(orderId);
			riskcontrolnotifyBean.setParamExt(paramExt);
			//发送请求
			riskcontrolnotifyCall.setData(riskcontrolnotifyBean);
			riskcontrolnotifyCall.callService();
			//Logger.verifyEquals(ECode.SUCCESS, riskcontrolnotifyCall.getCode(), "验证code");
			//数据库验证
			DefaultWapper database = new DefaultWapper();
			Logger.verifyEquals(1,database.selectOrderByOderId(orderId).get(0).get("iRiskVerifiedStatus"),
					"验证风控状态");		
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_RiskControlNotify_002() {
		Logger.start(true,"风控通知拒绝，成功");
		try {
			//创建订单
			Logger.comment("前置数据准备");
			PlaceOrderResp placeOrderResp=new OrderCallService().createM2cOrder();

			int orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			int sellerId =placeOrderResp.getOrderList().get(0).getSellerId();
			int userId =placeOrderResp.getUserId();         
			int tradingId = placeOrderResp.getTradingId();
			BigDecimal totalPrice =  placeOrderResp.getPayAmount();// 支付金额

			new OrderCallService().orderPayRequest(userId, totalPrice, tradingId);
			Map paramExt = new HashMap<String, String>();
			paramExt.put("Status", "rejected");
			
			//参数
			riskcontrolnotifyBean.setOrderId(orderId);
			riskcontrolnotifyBean.setParamExt(paramExt);
			//发送请求
			riskcontrolnotifyCall.setData(riskcontrolnotifyBean);
			riskcontrolnotifyCall.callService();
			//Logger.verifyEquals(ECode.SUCCESS, riskcontrolnotifyCall.getCode(), "验证code");
			//数据库验证
			DefaultWapper database = new DefaultWapper();
			Logger.verifyEquals(-1,database.selectOrderByOderId(orderId).get(0).get("iRiskVerifiedStatus"),
					"验证风控状态");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_RiskControlNotify_003() {
		Logger.start(true,"风控通知通过，成功");
		try {
			//创建订单
			Logger.comment("前置数据准备");
			PlaceOrderResp placeOrderResp=new OrderCallService().createM2cOrder();

			int orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			int sellerId =placeOrderResp.getOrderList().get(0).getSellerId();
			int userId =placeOrderResp.getUserId();         
			int tradingId = placeOrderResp.getTradingId();
			BigDecimal totalPrice =  placeOrderResp.getPayAmount();// 支付金额

						
			new OrderCallService().orderPayRequest(userId, totalPrice, tradingId);
			Map paramExt = new HashMap<String, String>();
			paramExt.put("Status", "pass");
			
			//参数
			riskcontrolnotifyBean.setOrderId(orderId);
			riskcontrolnotifyBean.setParamExt(paramExt);
			//发送请求
			riskcontrolnotifyCall.setData(riskcontrolnotifyBean);
			riskcontrolnotifyCall.callService();
			//Logger.verifyEquals(ECode.SUCCESS, riskcontrolnotifyCall.getCode(), "验证code");
			//数据库验证
			DefaultWapper database = new DefaultWapper();
			Logger.verifyEquals(2,database.selectOrderByOderId(orderId).get(0).get("iRiskVerifiedStatus"),
					"验证风控状态");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_RiskControlNotify_004() {
		Logger.start(false,"订单号为空，失败");
		try {
			Map paramExt = new HashMap<String, String>();
			paramExt.put("Status", "auditing");
			//参数
			
			riskcontrolnotifyBean.setParamExt(paramExt);
			//发送请求
			riskcontrolnotifyCall.setData(riskcontrolnotifyBean);
			riskcontrolnotifyCall.callService();
			Logger.verifyEquals("fail", riskcontrolnotifyCall.getReturnData(), "验证data");
							
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}